﻿@using Classified.Domain.Entities
@using MvcPaging
@using Classified.Service;
@model IPagedList<ClassifiedAd>
@{
    ViewBag.Title = ViewBag.CategoryName;
    Layout = "~/Views/Shared/_Layout.cshtml";
    List<string> list = ViewBag.Attributes;
    List<ClassifiedCategoryAttribute> attr = ViewBag.AllList;
    var classified = new List<ClassifiedAd>();
    Session.Add("Classifidlist", classified);
}
<script>
    $(".ata").live("click", function () {
        var id = $(this).attr("data-id");
        $("#" + id).removeAttr("checked");
        $("#frmSubmit").click();

    });
</script>
<div class="span3">
    @*@Html.Action("GetCategoryById", "ClassifiedAds", new { id = ViewBag.CategoryId })*@
    @Html.Action("GetAttributelistByid", "ClassifiedAds", new { id = ViewBag.CategoryId, filterBy = list })
</div>
<div class="span8" style="width: 835px;">
    @if (list != null && list.Count > 0)
    {
        <ul class="nav nav-pills">
            <li><a>Filter By :</a></li>
            @foreach (var i in attr)
            {


                if (list.Count > 0)
                {
                    var data = new AttributeValue();
                    foreach (var val in list)
                    {
                        var id = Convert.ToInt32(val);
                        data = i.AttributeValues.Find(x => x.Id == id);
                        if (data != null)
                        {
                <li><a class="ata" data-id="@data.Id">@data.Value</a></li>
                            break;
                        }

                    }
                }
            }
        </ul>
    }
    else
    {
        <h2>
            Result for :<small> @ViewBag.CategoryName</small>
        </h2>
           
    }
    <div class="clear">
    </div>
    <table class="table">
        @foreach (var item in Model.Where(x=>x.IsEnhanced))
        {
            <tr>
                <td class="table-img">
                    <div class="list-item-pic thumbnail">
                    @if (item.ClassifiedPicture.Count == 0)
                    {
                        <img src="/Images/120/90/images/no-image.jpg" alt="@item.Title"
                             title="@item.Title"/>
                    }
                    else
                    {
                        <img src="/Images/120/90/classified/@item.ClassifiedPicture.FirstOrDefault().ImageGuid"  alt="@item.Title"
                             title="@item.Title"/>
                    }
					<span class="paid-customer">&nbsp;</span>
                    </div>
                    
                </td>
                <td>
                    <h5>@item.Title</h5>
                    
                    <p>
                        @if (item.Description.Length > 200)
                        {<text>@Html.Raw(@item.Description.Substring(0, 200) + "...")
                         </text>
                        }
                        else
                        {
                            <text>
                                @Html.Raw(item.Description)
                            </text>
                        }</p>
                    

                </td>
                <td width="15%">
                    @if (item.Price != 0)
                    {<p class="price">
                         @SeService.GetCurrentCode(item.Id) @item.Price</p>}
                                                 <span style="display: block;margin-bottom: 6px;"><i class="icon-comment"></i>comment(@item.ClassifiedComments.Count())</span>
                                               <b class="clear"></b>
                        <a class="btn" href="@Url.Action("Details", "ClassifiedAds", new { id = item.Id, seName = SeService.GetSeName(item.Title) })">
                            Read More »</a>
                </td>
            </tr>
        }
        @foreach (var item in Model.Where(x=>x.IsEnhanced == false))
        {
            <tr>
                <td class="table-img">
                     <div class="thumbnail">
                    @if (item.ClassifiedPicture.Count == 0)
                    {
                        <img src="/Images/120/90/images/no-image.jpg" alt="@item.Title"
                             title="@item.Title"/>
                    }
                    else
                    {
                        <img src="/Images/120/90/classified/@item.ClassifiedPicture.FirstOrDefault().ImageGuid"  alt="@item.Title"
                             title="@item.Title"/>
                    }
                    </div>
                
                </td>
                <td>
                    <h5>@item.Title</h5>
                  
                    <p>
                        @if (item.Description.Length > 200)
                        {<text>@Html.Raw(item.Description.Substring(0, 200) + "...")
                         </text>
                        }
                        else
                        {
                            <text>
                                @Html.Raw(item.Description)
                            </text>
                        }</p>
                   

                </td>
                  <td>
                    @if (item.Price != 0)
                    {<p class="price">
                         @SeService.GetCurrentCode(item.Id) @item.Price</p>}
                                                 <span style="display: block;margin-bottom: 6px;"><i class="icon-comment"></i>comment(@item.ClassifiedComments.Count())</span>
                                                 <b class="clear"></b>
                        <a class="btn" href="@Url.Action("Details", "ClassifiedAds", new { id = item.Id, seName = SeService.GetSeName(item.Title) })">
                            Read More »</a>
                </td>
            </tr>
        }
    </table>

    <div class="clear">
    </div>
    @if (Model.TotalItemCount > 0)
    {
        <div class="pagingContainer noprint">
            @Html.Pager(Model.PageSize, Model.PageNumber, Model.TotalItemCount)
        </div>
    }
</div>
<div class="row">
    <div class="span12">
        @Html.Action("RecentViewList", "Home")
    </div>
</div>
